clear
%% PROBLEM
d = 1;
x_bound = [0,1];
OptSet.sol = [0.1;0.3;0.5;0.7;0.9];
OptSet.fval = 0;
OptSet.radius = 0.01;
epsilon = [0.1,0.01,0.001,0.0001];
edge = [0.05,0.05,0.05,0.05];
% edge = [0.012,0.004,0.0012,0.0004];

Problem.Dimension = d; % the dimension of the decision variable
Problem.LowerBound = x_bound(:,1)'; % the lower bound of the decision variable
Problem.UpperBound = x_bound(:,2)'; % the upper bound of the decision variable
Problem.NumObjFunc = 2; % the number of objective functons
%% ALGORITHM
N_max = round(100000/(1+2*d));
Algorithm.PopulationSize = size(OptSet.sol,1)*10;  % the population size of the ga
Algorithm.StopCriteria = [1,N_max];  % stop when the budget is exhausted
% Algorithm.StopCriteria = [2,100];  % stop when the number of generation is reached
Algorithm.pc = 0.9;  % the crossover probability
Algorithm.pm = 0.5;  % the mutation probability
Algorithmeta_c = 10;  % SBX index
Algorithmeta_m =20;  % mutation index
%% OPTIMIZATION
rep = 50;
TotalBudget = zeros(rep,length(epsilon));
OptNoFound = zeros(rep,length(epsilon));
TotalGeneration = zeros(rep,length(epsilon));
for iepsilon = 1:length(epsilon)
    OptSet.epsilon = epsilon(iepsilon);
    delta_f = OptSet.epsilon;
    delta_x = edge(iepsilon);
    Algorithm.ParetoType = [2, delta_f, delta_x];
    Problem.ObjFunc = @(x)ModifiedObj(@ObjValue,x,delta_x);  % the objective function
    for i = 1:rep
        disp(['epsilon: ',num2str(epsilon(iepsilon)),', replication: ',num2str(i),'.'])
        tic
        [ParetoFront, ParetoSet, GenerationNum, EvaluationNum, OptSetRemain]...
            = nsga2_multimodal_test(Problem, Algorithm, OptSet);
        toc
        TotalBudget(i,iepsilon) = EvaluationNum*(1+2*d);
        OptNoFound(i,iepsilon) = size(OptSetRemain,1);
        TotalGeneration(i,iepsilon) = GenerationNum;
    end
end
